<?php
/**
 * Created by PhpStorm.
 * User: zskj
 * Date: 2019/2/25
 * Time: 16:53
 */

namespace app\api\controller;

use app\common\Base;
use app\tools\Helper;

class Sms extends Base{

    function send(){

        $mobile = $this->getParam('mobile', 0);
        $is_check = $this->getParam('is_check', 0);
        $code = Helper::smsCode(6);

        $where = [
            'mobile'=> $mobile,
            'status'=> ['<>', 5]
        ];

        if($is_check){
            $info = db('company')->where($where)->field('id, account, name')->find();
            if(!$info){
                return fail("ACCOUNT_NOT_EXIST");
            }
        }

        $sms = new \app\tools\Sms();
        $sms->send($mobile, $code);

        return success([]);

    }

}